from dao.BaseDao import BaseDao

class StudentDao(BaseDao):
    def insert_student(self, name, age, grade):
        query = "INSERT INTO students (name, age, grade) VALUES (%s, %s, %s)"
        values = (name, age, grade)
        return self.execute_sql(query, values)

    def update_student(self, student_id, name, age, grade):
        query = "UPDATE students SET name = %s, age = %s, grade = %s WHERE id = %s"
        values = (name, age, grade, student_id)
        return self.execute_sql(query, values)

    def delete_student(self, student_id):
        query = "DELETE FROM students WHERE id = %s"
        values = (student_id,)
        return self.execute_sql(query, values)

    def get_all_students(self):
        query = "SELECT * FROM students"
        return self.execute_query(query)

    def get_student_by_id(self, student_id):
        query = "SELECT * FROM students WHERE id = %s"
        values = (student_id,)
        return self.execute_query(query, values)

    def get_student_by_name(self, name):
        query = "SELECT * FROM students WHERE name = %s"
        values = (name,)
        return self.execute_query(query, values)

    def get_students_by_page(self, page_number, page_size):
        offset = (page_number - 1) * page_size
        query = "SELECT * FROM students LIMIT %s OFFSET %s"
        values = (page_size, offset)
        return self.execute_query(query, values)